import {
	useStore
} from '@/store/pinia.js'
import {
	settingStore
} from '@/store/setting.js'
import{
	diffTokenTime
}from '@/utils/tokenAuth.js'
import http from "@/utils/http";
import utils from "@/utils/utils.js";

export default function installPlugins(app) {
		// console.log(item, 'router list item')
		uni.addInterceptor("request", {
			invoke(args) { // 调用前拦截
				//获取用户的token
				if(args.url&&args.url.endsWith("/oauth")){
					return true;
				}
				if(diffTokenTime()==true){
					uni.switchTab({
						url: "/pages/login/login"
					})
				}
				const token = uni.getStorageSync("token");
				args.header.token=token;
				return true
			},
			fail(err) { // 失败回调拦截 
				console.log(err);
			},
		})

	// 模态框对象
	// app.config.globalProperties.$modal = modal
	//tagtop
	// app.config.globalProperties.$tab = tab
	//全局注册axios
	app.config.globalProperties.$http = http
	app.config.globalProperties.$utils = utils
	//全局注册pinia的store
	app.config.globalProperties.$pinia = useStore()
	app.config.globalProperties.$settingStore = settingStore()
	//后端图片的保存文件夹
	//部署打包要修改，要改成不带ip地址的
	app.config.globalProperties.$basePhotoUrl = "/upload"
	//本地开发用
	// app.config.globalProperties.$basePhotoUrl = "http://localhost:8080/upload"
}